/**
 * 
 */
package wangjg.game.widget;

import wangjg.game.android.AnImage;
import wangjg.game.layer.Graphics;
import wangjg.game.layer.Image;
import wangjg.game.layout.PercentProperty;
import android.graphics.Bitmap;

/**
 * @author wangjg
 *
 */
public class ImageBox extends Widget{
	private PercentProperty pp = new PercentProperty();
	private Image image;
	
	public ImageBox(float widthPercent, float heightPercent) {
		this(widthPercent, heightPercent, 0);
	}
	
	public ImageBox(float widthPercent, float heightPercent, int spacing) {
		pp.setWidthPercent(widthPercent);
		pp.setHeightPercent(heightPercent);
		pp.setAbsSpacing(spacing);
	}

	public void setBitmap(Bitmap bitmap) {
		this.image = new AnImage(bitmap);;
	}

	public void setImage(Image image) {
		this.image = image;
	}
	
	public void paint(Graphics g) {
		if(this.getVisible()!=PercentProperty.DISPLAY_VISIBLE){
			return;
		}
		if(image==null){
			return;
		}
//		g.drawRect(pp.getAbsX(), pp.getAbsY(), pp.getAbsWidth(), pp.getAbsHeight());
		g.drawRegion(image, 0, 0, pp.getAbsWidth()/2, pp.getAbsHeight()/2, 11, pp.getAbsX(), pp.getAbsY(), 0);
	}

	@Override
	public PercentProperty getPercentProperty() {
		return pp;
	}

}